package com.han.nettytestdemo.connector.netty.client;


import com.han.nettytestdemo.connector.CRC16M;
import com.han.nettytestdemo.connector.LogUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class JsonEncoder extends MessageToByteEncoder<String> {

    @Override
    protected void encode(ChannelHandlerContext ctx, String user, ByteBuf buf)
            throws Exception {

        byte[] sbuf = CRC16M.getSendBuf(user);
//        System.out.println(CRC16M.getBufHexStr(sbuf));
        LogUtil.e(ClientHandler.TAG, "encode" + CRC16M.getBufHexStr(sbuf));
//        String json = JsonUtil.toJSON(user);
        ByteBuf byteBuf = Unpooled.wrappedBuffer(sbuf);
        ctx.writeAndFlush(byteBuf);
    }

}
